package com.applet.applet_shangcheng.dao;

import com.applet.applet_shangcheng.entity.IntegralGoods;
import com.applet.applet_shangcheng.entity.IntegralMalls;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IntegralGoodsMapper {

    @Select({
            "select id,goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status from tb_integral_goods where status =1"
    })
    List<IntegralGoods> findAll();

    @Select({
            "select id,goods_id,goods_name,goods_title,image,integral,sale_num from tb_integral_goods where status =1 and sort_id=#{sortId} and integral>=#{min} and integral<=#{max}"
    })
    List<IntegralGoods> selectGoods(@Param("sortId") String sortId, @Param("min") int min, @Param("max") int max);

    @Select({
            "select id,goods_id,goods_name,goods_title,image,integral,sale_num from tb_integral_goods where status =1 and sort_id=#{sortId} and integral>100"
    })
    List<IntegralGoods> selectGoodsAndMax(@Param("sortId") String sortId);

    @Select({
//            "select id,goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status from tb_integral_goods where status = 1 and id = #{id}"
            "select id,goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status from tb_integral_goods where id = #{id}"
    })
    IntegralGoods findById(@Param("id") int id);

    @Select({
            "select id,goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status from tb_integral_goods where id = #{id}"
    })
    IntegralGoods findByIdAll(@Param("id") int id);

    @Select({
            "select id,goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status from tb_integral_goods where status = 1 and goods_id = #{goodsId}"
    })
    IntegralGoods findByGoodsId(@Param("goodsId") String goodsId);

    @Insert({
            "insert into tb_integral_goods ( goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status) values ( #{goodsId},#{goodsName},#{goodsTitle},#{image},#{images},#{goodsDetail},#{integral},#{connection},#{saleNum},#{createTime},#{updateTime},#{sortId},#{status})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertIntegralGoods(IntegralGoods integralGoods);

    @Update({
            "update tb_integral_goods set goods_name=#{goodsName},goods_title=#{goodsTitle},image=#{image},images=#{images},goods_detail=#{goodsDetail},integral=#{integral},connection=#{connection},sale_num=#{saleNum},update_time=#{updateTime},sort_id=#{sortId},status=#{status} where id=#{id}"
    })
    int updateGoods(IntegralGoods integralGoods);

    @Delete({
            "delete from tb_integral_goods where id =#{id}"
    })
    int deleteGoods(@Param("id") int id);

    @Select({
            "SELECT MAX(integral) FROM tb_integral_goods"
    })
    int findByIntegral();

    @Select({
            "SELECT id,goods_id,goods_name,goods_title,image,integral,sale_num FROM tb_integral_goods where goods_id=#{goodsId} "
    })
    IntegralGoods getGoodsId(@Param("goodsId") int goodsId);

    @Select({
            "SELECT id,goods_id,goods_name,goods_title,image,integral,sale_num FROM tb_integral_goods where goods_name=#{goodsName}"
    })
    IntegralGoods getGoodsName(@Param("goodsName") String goodsName);

    @Select({
            "select id,goods_id,goods_name,goods_title,image,images,goods_detail,integral,connection,sale_num,create_time,update_time,sort_id,status from tb_integral_goods where status = 1 and goods_name = #{goodsName}"
    })
    IntegralGoods findByGoodsName(@Param("goodsName") String goodsName);

    Page<IntegralGoods> findAll1(String queryString);

    Page<IntegralMalls> calssFindAll(String queryString);

    @Delete({
            "delete from tb_integral_malls where id =#{id}"
    })
    int deleteGoodsclass(int id);

    @Insert({
            "insert into tb_integral_malls (table_t,sort_id,sort_name) values (#{tableT},#{sortId},#{sortName}) "
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertGoodsClass(IntegralMalls integralMalls);

    @Select({
            "select * from tb_integral_malls where sort_id =#{parseInt}"
    })
    IntegralMalls findBySortId(@Param("parseInt")int parseInt);

    List<IntegralGoods> findAllS();

}

